package com.yaolong.api.modules.utils;

import com.yaolong.api.modules.opms.service.OpmsFixFamilyInfoService;
import com.yaolong.api.modules.sys.dto.UserInfoDto;
import com.yaolong.api.modules.sys.po.RoleInfo;
import com.yaolong.api.modules.sys.service.ISysUserInfoService;
import com.yaolong.commons.utils.MapperUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author yuelian
 * @version V1.0.0
 * @program 判断角色工具类
 * @description
 * @create 2023-03-09 22:14
 **/
@Component
public class CheckRoleUtils {
    @Autowired
    private ISysUserInfoService iSysUserInfoService;

    @Autowired
    private OpmsFixFamilyInfoService opmsFixFamilyInfoService;

    //获取角色
    public List<RoleInfo> getRoleInfo() {
        UserInfoDto userInfoDto = iSysUserInfoService.userInfoByContext();
        return MapperUtils.copyList(userInfoDto.getRoles(), RoleInfo.class);
    }

    //判断是否是管理员
    public static boolean checkRole(List<RoleInfo> roles) {
        boolean f = false;
        for (RoleInfo role : roles) {
            if ("ROLE_ADMIN".equals(role.getValue()) || "ROLE_AUDIT".equals(role.getValue())) {
                //管理员 审核员
                f = true;
                break;
            }
            if ("ROLE_RESIDEBTS".equals(role.getValue())) {
                //居民员
                f = false;
            }
        }
        return f;
    }

    public static boolean checkAdminRole(List<RoleInfo> roles) {
        boolean f = false;
        for (RoleInfo role : roles) {
            if ("ROLE_ADMIN".equals(role.getValue())) {
                //管理员 审核员
                f = true;
                break;
            }
        }
        return f;
    }

}
